/**
 * 
 */
package com.base.myproject.client.busi.b2c.manager;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BaseObject;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.storeslist.StoreCcode;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.SystemMessage;
import com.base.myproject.client.tools.SendServlet;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.fx.FxConfig;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;

/**
 * 下单工作台
 * 负责用户下单后，备货，发货，形成收付款单据
 * @author zgw
 *2009-8-27 上午07:45:22
 * javazgw@gmail.com
 */
public final class OrderWorkbench extends ContentPanel{

	
	GroupingStore<BusiObject> groupstore;
	SelectionListener<ButtonEvent> listener;
	BaseStore<BusiObject> shoppingstore;
	Grid grid;
	BaseGrid<BusiObject> shoppinggrid ;
	java.util.LinkedList<? extends BaseObject> loolinklist;
	Dialog dialog;
	DateField lastshipdatefield;
//	  BaseGridEditor   ccodefield;
	BaseComboBoxForm<ModelData> ccodefield ;
	FormPanel formpanel;
	BasePagingLoader< PagingLoadResult<BusiObject>>  loder ;
	Html storelasthtml ;
	ContentPanel shoppingcp;
	public OrderWorkbench()
	{
		init();
	}
	void init()
	{
		createscript();
		TableLayout tl = new TableLayout(5);
		
		this.setLayout(tl);
		setHeight("700px");
		setWidth("720px");
		initListener();
		initstore();
		initLeftPanel();
		initWidget();
		initShopping();
		
	}
	void initstore()
	{
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("ordercode");
		type.addField("orderdate");
		type.addField("b2cgcode");
		type.addField("b2cgname");
		type.addField("ccode");
		type.addField("qty");
		type.addField("icode");
		type.addField("status");
		
		StoreInfo info = new StoreInfo();

		info.setTablename("b2clistorderg");
		info.setSql("select * from b2clistorderg order by ordercode");
		info.setKeyname(new String[]{"icode"});
		SendServlet ss = new SendServlet();
		loder = ss.getBaseLoaderX(type,info);
		 groupstore = new GroupingStore<BusiObject>(loder);  
		 loder.load();
		 groupstore.groupBy("ordercode");  
//		 loder.addLoadListener(new LoadListener(){
//			 public void loaderLoad(LoadEvent e){
//				 System.out.println("group ............");
//			 }
//		 });
	}
	@SuppressWarnings("unchecked")
	void initWidget()
	{
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig ordercode = new ColumnConfig("ordercode", "订单号", 100);

		columns.add(ordercode);
		
		ColumnConfig orderdate = new ColumnConfig("orderdate", "下订单日期", 100);

		columns.add(orderdate);
		ColumnConfig ccode = new ColumnConfig("ccode", "客户名", 100);

		columns.add(ccode);
		ColumnConfig b2cgcode = new ColumnConfig("b2cgcode", "商品名称", 100);

		columns.add(b2cgcode);
		ColumnConfig qty = new ColumnConfig("qty", "数量", 50);
	
		columns.add(qty);
		
		ColumnConfig storeqty = new ColumnConfig("storeqty", "库存数量", 50);
		GridCellRenderer<ModelData>	storeqtyrenderer = new GridCellRenderer<ModelData>() {

		      public Button render(ModelData model, String property, ColumnData d, int rowIndex,
		          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
		    	  //javascript:show_last_store("+model.get("b2cgcode")+");
		    //	  return "" + ("<a  href=\"javascript:void(0)\"  onclick=\"alert('ff'+$wnd.event.clientY );\" ><img src='../images/baseimage/store.png' /></a>" );
		    	  
//		    	  Html html = new Html("<img src='../images/baseimage/store.png' />"); 
//		    	  html.addListener(EventType., listener);
		    	  Button button = new Button("");
		    	  button.setId("storelast");
		    	  button.setData("cgicode",model.get("b2cgcode"));
		    	  button.setIconStyle("laststore");
		    	  button.addSelectionListener(listener);
		    	  return button; 
		      
		      }
		    };
		    storeqty.setRenderer(storeqtyrenderer) ;
		columns.add(storeqty);

		ColumnConfig status = new ColumnConfig("status", "状态", 50);

		
		
		
		GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {

	      public String render(ModelData model, String property, ColumnData d, int rowIndex,
	          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {

	       if(model.get(property)==null)
	        return "" ;

	       return SystemMessage.getstatus(model.get(property)+"");
	      }
	    };
		status.setRenderer(renderer);
		columns.add(status);
		final ColumnModel cm = new ColumnModel(columns);
		
		
		  GroupingView view = new GroupingView();  
		    view.setShowGroupedColumn(false);  
		    view.setForceFit(true);  
		    view.setGroupRenderer(new GridGroupRenderer() {  
		      public String render(GroupColumnData data) {  
		        String f = cm.getColumnById(data.field).getHeader();  
		        String l = data.models.size() == 1 ? "Item" : "Items";  
		        return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";  
		      }  
		    });  
		 grid = new Grid(groupstore, cm);  
		cbs.setSelectionMode(SelectionMode.MULTI);
//		grid.getSelectionModel().setSelectionMode(SelectionMode.MULTI);  
		grid.setSelectionModel(cbs);
		
		grid.setView(view);
		grid.setAutoHeight(true);
	//	grid.setWidth("400px");
		grid.setAutoWidth(true);
		TableData td = new TableData();
		td.setColspan(4);
		td.setVerticalAlign(VerticalAlignment.TOP);
		ContentPanel cp = new ContentPanel();
		cp.setFrame(false);
		cp.setHeading("用户下订单商品列表");
		cp.setStyleName("basepanelmargin");
		cp.add(grid);
		add(cp,td);
	}
	void initLeftPanel()
	{
		ContentPanel cp = new ContentPanel();
		cp.setHeading("分组显示方式");
		cp.setStyleName("basepanelmargin");
		cp.setHeaderVisible(true);
		cp.setFrame(false);
		VerticalPanel vp = new VerticalPanel();
		
		Button groupbyordercode = new Button("根据订单分组");
		Button groupbyorderdate = new Button("根据下订单日期分组");
		Button groupbyb2cgcode = new Button("根据相同产品分组");
		Button groupbyccode = new Button("根据相同客户名分组");
		groupbyordercode.setWidth("130px");
		groupbyorderdate.setWidth("130");
		groupbyb2cgcode.setWidth("130px");
		groupbyccode.setWidth("130px");
		vp.add(groupbyordercode);
		vp.add(groupbyorderdate);
		vp.add(groupbyb2cgcode);
		vp.add(groupbyccode);
		groupbyordercode.addSelectionListener(listener);
		groupbyorderdate.addSelectionListener(listener);
		groupbyb2cgcode.addSelectionListener(listener);
		groupbyccode.addSelectionListener(listener);
		TableData td = new TableData();
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setColspan(1);
//		add(vp,td);
		vp.add(initExcPanel());
		cp.add(vp);
		add(cp,td);
	}
	ContentPanel initExcPanel()
	{
		ContentPanel cp = new ContentPanel();
		cp.setHeading("操作");
		cp.setStyleName("basepanelmargin");
		cp.setHeaderVisible(true);
		cp.setFrame(false);
		cp.setBodyBorder(false);
		VerticalPanel vp = new VerticalPanel();
		
		Button Stocking = new Button("通知备货");
		Button shipsend = new Button("确认备货");
		Button shipsendcancel = new Button("取消备货");
		Button shipping = new Button("安排发货");
		Button update = new Button("update");
		Button delete = new Button("delete");
		Button insert = new Button("insert");
		
		Stocking.setWidth("130px");
		shipping.setWidth("130px");
		shipsend.setWidth("130px");
		shipsendcancel.setWidth("130px");
		vp.add(Stocking);
		vp.add(shipsend);
		vp.add(shipsendcancel);
		vp.add(shipping);
//		vp.add(update);
//		vp.add(delete);
//		vp.add(insert);

		Stocking.addSelectionListener(listener);
		shipping.addSelectionListener(listener);
		shipsendcancel.addSelectionListener(listener);
		shipsend.addSelectionListener(listener);
		update.addSelectionListener(listener);
		delete.addSelectionListener(listener);
		insert.addSelectionListener(listener);
		cp.add(vp);
		
		return cp;
	}
	/**
	 * 备货
	 */
	void initShopping()
	{
		shoppingcp = new ContentPanel();

		shoppingcp.setFrame(false);
		shoppingcp.setCollapsible(true);  
		//cp.setHeaderVisible(false);
		shoppingcp.setBodyBorder(false);
		shoppingcp.setHeading("本次备货商品");
		shoppingcp.setWidth("680px");
		shoppingcp.setHeight("28" +
				"0px");
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		//CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		//cbs.setSelectionMode(SelectionMode.MULTI);
		//columns.add(cbs.getColumn());
		ColumnConfig b2cgcode = new ColumnConfig("b2cgcode", "商品编码", 80);

		columns.add(b2cgcode);
		ColumnConfig b2cgname = new ColumnConfig("b2cgname", "商品名称", 100);

		columns.add(b2cgname);
		ColumnConfig qty = new ColumnConfig("qty", "备货数量", 150);
		TextField<String> qtytext = new TextField<String>();
		qty.setEditor(new CellEditor(qtytext));
		columns.add(qty);
	
		ColumnConfig ordercode = new ColumnConfig("ordercode", "订单号", 100);

		columns.add(ordercode);
//		ColumnConfig ccode = new ColumnConfig("ccode", "客户编码", 100);

//		columns.add(ccode);
//		ColumnConfig orderdate = new ColumnConfig("orderdate", "客户下订单日期", 100);

	//	columns.add(orderdate);
		ColumnConfig shoppingdate = new ColumnConfig("shoppingdate", "备货日期", 100);

		columns.add(shoppingdate);

		final ColumnModel cm = new ColumnModel(columns);
		
		 shoppingstore = new BaseStore();
		
//		JDBCModelData md = new JDBCModelData();
//		shoppingstore.add(md)
		shoppinggrid = new BaseGrid<BusiObject>(shoppingstore,cm,true,true);
		shoppinggrid.setHeight("180px");
	//	shoppinggrid.setSelectionModel(GridSelectionModel);
		
	
		shoppingcp.add(shoppinggrid);
		TableData td = new TableData();
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setColspan(5);
		shoppingcp.setStyleName("basepanelmargin");
		shoppingcp.setScrollMode(Scroll.AUTO);
		
//		shoppingcp.setVisible(true);
		add(shoppingcp,td);
	}
	void initListener()
	{
		
		 listener = new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				System.out.println(ce.getButton().getText());
				System.out.println(ce.getButton().getId());
			
				
				
				if(ce.getButton().getText().equals("根据订单分组"))
				{
					groupstore.groupBy("ordercode");	
				}
				else if(ce.getButton().getText().equals("根据相同产品分组"))
				{
					groupstore.groupBy("b2cgcode");	
				}
				else if(ce.getButton().getText().equals("根据相同客户名分组"))
				{
					groupstore.groupBy("ccode");	
				}
				else if(ce.getButton().getText().equals("根据下订单日期分组"))
				{
					groupstore.groupBy("orderdate");	
				}
				
				else if(ce.getButton().getText().equals("通知备货"))
				{
					/*java.util.Map<String, Object> hmap = new java.util.HashMap<String, Object>();
					hmap.put("b2cgcode", "20000005");
					hmap.put("shoppingdate", "2005-9-9");
					JDBCModelData md = new JDBCModelData(hmap);
					shoppingstore.add(md);
					*/
					
					 if (shoppingcp.isVisible()) {  
						// shoppingcp.el().slideOut(Direction.DOWN, FxConfig.NONE);  
						 shoppingcp.el().blink(FxConfig.NONE);  
				        } else {  
				        	//
				        }  
					List<BusiObject> l = grid.getSelectionModel().getSelectedItems();
					Date daynow = new Date();
					DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
					String shoppingdate = fmt.format(daynow);
					for(int i=0;i<l.size();i++)
					{
						//System.out.println(((BaseModelData)l.get(i)).get("ordercode"));
						String status = ((BaseModelData)l.get(i)).get("status");
						String ordercode = ((BaseModelData)l.get(i)).get("ordercode");		
						String b2cgcode = ((BaseModelData)l.get(i)).get("b2cgcode");
						if(status.equals("8"))
						{
							Info.display("警告", "此商品编号为："+b2cgcode+"已经加入到备货商品里\n");
							continue;
						}
						
						String ccode = ((BaseModelData)l.get(i)).get("ccode");
					
						String qty = ((BaseModelData)l.get(i)).get("qty");
						String b2cgname = ((BaseModelData)l.get(i)).get("b2cgname");
						String orderdate = ((BaseModelData)l.get(i)).get("orderdate");
//						String icode = ((BaseModelData)l.get(i)).get("icode");
						
						String icode =groupstore.getAt(groupstore.indexOf(l.get(i))).get("icode");
						java.util.Map<String, Object> hmap = new java.util.HashMap<String, Object>();
						hmap.put("ordercode", ordercode);
						hmap.put("ccode", ccode);
						hmap.put("b2cgcode", b2cgcode);
						hmap.put("cgicode", b2cgcode);
						hmap.put("qty", qty);
						hmap.put("b2cgname", b2cgname);
						hmap.put("orderdate", orderdate);
						hmap.put("shoppingdate", shoppingdate);
						hmap.put("icode", icode);
						hmap.put("upicode",icode);
						hmap.put("busistatus","8");
			
						//hmap.put("icode", icode);
						BusiObject md = new BusiObject(hmap);
						shoppingstore.add(md);
					}
					java.util.Vector<String> v = new java.util.Vector<String>();
					
					for(int i=0;i<l.size();i++)
					{
//						System.out.println(l.get(i).getBusistatus());
						groupstore.getRecord(l.get(i)).set("status", "8");
//						grid.getSelectionModel().getSelectedItem().
						// 8 参看SystemMessage 中状态的定义
						//String updatesql = "update b2clistorderg set status='8' where icode='"+l.get(i).get("icode")+"'";
						//v.add(updatesql);
					}
					//SendServlet ss = new SendServlet();
					//ss.ExcJDBCSQL(v);
					
					
				}
				else if(ce.getButton().getText().equals("安排发货"))
				{
					final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
					.create(com.base.myproject.client.tools.GreetingService.class);

			//System.out.println(ll.size());
					greetingService.getBaseObject("sql query","com.base.myproject.client.busi.BO.ListOrderObject",
					new AsyncCallback<java.util.LinkedList<BusiObject> >() {
						public void onFailure(Throwable caught) {
							// Show the RPC error message to the user
							System.out.println("error");
						}

						public void onSuccess(java.util.LinkedList<BusiObject>  result) {
					//		.out.println(result.size());
//							for(int i=0;i<result.size();i++)
//							{
//								JDBCModelData md = new JDBCModelData(result.get(i).getMap());
//								shoppingstore.add(md,false);
//							}
							shoppingstore.insert(result, shoppingstore.getCount());
							//result.get(0).delete();
						//	System.out.println("icode="+result.get(1).getProperties().get("icode"));
							loolinklist =result;
						}
					});
				}
				else if(ce.getButton().getText().equals("确认备货"))
					
				{
					if(dialog == null)
						getShippreDailog();
					dialog.show();
				}
				else if(ce.getButton().getText().equals("取消备货"))
				{
					List<BusiObject> l = grid.getSelectionModel().getSelectedItems();
					Date daynow = new Date();
					DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
					String shoppingdate = fmt.format(daynow);
					java.util.Vector<String> v = new java.util.Vector<String>();
					for(int i=0;i<l.size();i++)
					{
						String updatesql = "update b2clistorderg set status='32' where icode='"+l.get(i).get("icode")+"'";
						String storeslistccodegupdatesql = "update storeslistccodeg set busistatus='32' where upicode='"+l.get(i).get("icode")+"' and busistatus='8'";
						
						v.add(storeslistccodegupdatesql);
						v.add(updatesql);
						
						groupstore.getRecord(l.get(i)).set("status", "32");
					}
					
				
					SendServlet ss = new SendServlet();
					ss.ExcJDBCSQL(v);
					shoppingstore.removeAll();
				}
				else if(ce.getButton().getText().equals("确定"))
				{	
			
					
					if(formpanel.isValid())
					{
						
						StoreCcode sp = new StoreCcode(null);
						DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
						String date = fmt.format(lastshipdatefield.getValue());
						BusiObject bo = new BusiObject();
						bo.set("ccode", ccodefield.getValueCode());
						bo.set("lastshipdate", date);
						List<BusiObject> l = new java.util.LinkedList<BusiObject>();
						l.add(bo);
						List<BusiObject> l2 =   shoppingstore.getModels();
						java.util.Vector<String> v = new java.util.Vector<String>();
				
						for(BusiObject bochile :l2)
						{
							bochile.set("ccode", ccodefield.getValueCode());
							
							bochile.set("cgicode", bochile.get("b2cgcode"));
					
							bochile.set("lastshipdate", date);
							
								// 8 参看SystemMessage 中状态的定义
							String updatesql = "update b2clistorderg set status='8' where icode='"+bochile.get("icode")+"'";
						
							v.add(updatesql);
				
						}
						sp.insertItem(l,l2);
				
						SendServlet ss = new SendServlet();
						ss.ExcJDBCSQL(v);
						dialog.hide();
						loder.load();
//						lastshipdatefield.set
						//ccodefield.setValue("");
						shoppingstore.removeAll();
					}
					else
					{
						//System.out.println("not isValid");
					}
					
				}
				else if(ce.getButton().getText().equals("update"))
				{
					/*List l = shoppinggrid.getSelectionModel().getSelectedItems();
					java.util.LinkedList<BaseObject> ll= new java.util.LinkedList<BaseObject>();
					for(int i=0;i<l.size();i++)
					{
						System.out.println(((JDBCModelData)l.get(i)).get("icode"));
						String icode = ((JDBCModelData)l.get(i)).get("icode")+"";
						for(int j=0;j<loolinklist.size();j++)
						{
							if(loolinklist.get(j).get("icode").equals(icode))
							{
								ll.add(loolinklist.get(j));
							}
						}
					}
					System.out.println("size="+ll.size());*/
					for(int i=0;i<shoppingstore.getCount();i++)
					{
						GWT.log(shoppingstore.getModels().get(i).getBusistatus()+"", null);
					}
					shoppingstore.getAt(0).setBusistatus(1);
				}
				else if(ce.getButton().getText().equals("delete"))
				{
//					System.out.println(shoppinggrid.getSelectionModel().getSelectedItems().get(0).getProperties().get("icode"));
//					shoppinggrid.getSelectionModel().getSelectedItems().get(0).setBusistatus(2);
					//shoppinggrid.getSelectionModel().getSelectedItems().get(1).setBusistatus(4);
					shoppingstore.setStatus(1, 8);
					shoppingstore.setStatus(2, 2);
					shoppingstore.setStatus(3, 4);
					shoppingstore.setStatus(4, 1);
					shoppingstore.setStatus(5, 8);
					shoppingstore.setStatus(6, 8);
					shoppingstore.setStatus(7, 4);
				}
				else if(ce.getButton().getText().equals("insert"))
				{
			/*		System.out.println(shoppinggrid.getSelectionModel().getSelectedItems().get(0).getProperties().get("b2cgcode"));
					System.out.println(shoppinggrid.getSelectionModel().getSelectedItems().get(0).getBusistatus());
					System.out.println(shoppinggrid.getSelectionModel().getSelectedItems().get(1).getBusistatus());
					shoppingstore.trySave();*/
/*					StoreCcode sp = new StoreCcode(null);
					BusiObject bo = new BusiObject();
					List<BusiObject> l = new java.util.LinkedList<BusiObject>();
					l.add(bo);
					
					BusiObject bochile = new BusiObject();
					BusiObject bochile2 = new BusiObject();
					bochile.set("qty", "100");
					bochile2.set("qty", "200");
					bochile.set("upicode", "200");
					bochile2.set("upicode", "200");
					List<BusiObject> lchile = new java.util.LinkedList<BusiObject>();
					lchile.add(bochile);
					lchile.add(bochile2);
					
					sp.insertItem(l, lchile);*/
					//System.out.println("---------"+ccodefield.getValue());
				}
				
				else if(ce.getButton().getId().equals("storelast"))
				{
					//System.out.println(ce.getButton().getData("cgicode"));
					String cgicode = ce.getButton().getData("cgicode");
					final DecoratedPopupPanel popup = new DecoratedPopupPanel(true);

					    popup.setStyleName("x-layout-popup");
					   
					    popup.setWidth("100px");
					   
					  final  Html html = new Html(" <img src='../images/baseimage/ajax-loader.gif' />");
						popup.add(html);
						int left = ce.getButton().getAbsoluteLeft() + 10;
			            int top = ce.getButton().getAbsoluteTop() + 10;
			            popup.setPopupPosition(left, top);
			            
			            SendServlet ss =new  SendServlet();
			          //  ss.getStringx("/gwtbase/BaseServlet", "Action=laststore&cgicode="+cgicode+"");
			            try {
							ss.sendServlet("BaseServlet",  "Action=laststore&cgicode="+cgicode+"", new RequestCallback()
							{

								@Override
								public void onError(Request request,
										Throwable exception) {
									// TODO Auto-generated method stub
									
								}

								@Override
								public void onResponseReceived(Request request,
										Response response) {
									// TODO Auto-generated method stub
								//	System.out.println(response.getText());
									html.setHtml(response.getText());
								}
								
							}
							);
						} catch (RequestException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
			            
						popup.show();
				}
				}
				  
				  
	
			
		};
	}
	protected void getShippreDailog()
	{
		dialog= new Dialog();
		dialog.setHeading("选择供应商");
		FormData fd = new FormData(130, 20);
		formpanel = new FormPanel();
		formpanel.setAutoHeight(true);
		formpanel.setAutoWidth(true);
	/*	 ccodefield = new TextField<String>();
		ccodefield.setName("codename");
		ccodefield.setAllowBlank(false);
		ccodefield.setFieldLabel("客户");*/

		//×××××××××××××××××××××××××
	/*	List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();
		ColumnConfig bcode = new ColumnConfig("ccode", "客户编码", 100);
		
		bocodecolumns.add(bcode);

		ColumnConfig bname = new ColumnConfig("cname", "客户名", 100);
		
		bocodecolumns.add(bname);
		
		ModelType bcodetype = new ModelType();
		bcodetype.setRoot("records") ;  
		bcodetype.setRecordName("record");  
		bcodetype.setTotalName("totle");
		bcodetype.addField("ccode");
		bcodetype.addField("cname");

		StoreInfo bcodeinfo = new StoreInfo();
		bcodeinfo.setTablename("ccode");
		bcodeinfo.setSql("select ccode,cname from ccode");
	     ccodefield = new BaseGridEditor(bocodecolumns,bcodetype,bcodeinfo,"ccode");
	    ccodefield.setName("codename");
	    ccodefield.setFieldLabel("客户");*/
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");


		type.addField("ccode");

		type.addField("cname");

		StoreInfo info = new StoreInfo();

		info.setTablename("ccode");
		 info.setSql("select ccode,cname from ccode");
			BaseStore<BaseModelData> ccodestore = new BaseStore<BaseModelData>(
					type, info);	
		ccodefield = new BaseComboBoxForm("ccode","cname",ccodestore);
		 ccodefield.setFieldLabel("客户");
	    
//	    GridCellRenderer<ModelData>	storeqtyrenderer = new GridCellRenderer<ModelData>() {
//
//		      public String render(ModelData model, String property, ColumnData d, int rowIndex,
//		          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
////		    	  if(model.get(property))
//		    return	  CodeNameMap.getInstance().getMap("ccode").get(model.get(property));
//		      }
//	    };
//	    ccodefield.set
	    //×××××××××××××××××××
		
//		DateField date = new DateField();  
	 //   date.setFieldLabel("Birthday");  
		lastshipdatefield =   new DateField();  
		
		lastshipdatefield.setAllowBlank(false);
		lastshipdatefield.setFieldLabel("最迟发货日期");
		
		formpanel.add(ccodefield,fd);
		formpanel.add(lastshipdatefield,fd);
		dialog.add(formpanel);
	//	dialog.setHideOnButtonClick(true);
		dialog.getButtonById(Dialog.OK).addSelectionListener(listener);
	
	}
	private native void createscript()/*-{
		$wnd.show_last_store = function(cgicode){
			
		
			
			@com.base.myproject.client.busi.b2c.manager.OrderWorkbench::aa(Ljava/lang/String;)(cgicode+"");
		}
	}-*/;
	
	static void aa(String cgicode)
	{
		
		final DecoratedPopupPanel popup = new DecoratedPopupPanel(true);
	//Popup popup = new Popup();
	    popup.setStyleName("x-layout-popup");
	    
//	    popup.setLayout(new FillLayout());
//	    popup.setShadow(true);
		popup.add(new Html("asdfasdf"));
		//popup.setPopupPosition(100	, 100);
		
		popup.show();
//		Window.alert(cgicode);
	}
}
